package com.lzb.yabbs.net;

import android.util.Log;

import com.alibaba.fastjson.JSONObject;
import com.lzb.yabbs.AppConfig;
import com.lzb.yabbs.dao.Board;
import com.lzb.yabbs.dao.Card;
import com.lzb.yabbs.interfaces.GetBoardCallback;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.io.IOException;
import java.util.List;

/**
 * Created by liuzaibing on 2015/9/9.
 */
public class GetBoardFromNet {
    public static void getBoards(String url, final GetBoardCallback getBoardCallback){
        OkHttpClientRequest.requestGet(url, null, new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {

            }

            @Override
            public void onResponse(Response response) throws IOException {
                String result=response.body().string();
                System.out.println("onResponse:"+result);
                List<Board> mBoards=JSONObject.parseArray(result,Board.class);
                if(mBoards.size()>0){
                    getBoardCallback.success(mBoards);
                }else {
                    getBoardCallback.fail(0);
                }
            }
        });
    }
}
